<?php
/* 
 * FieldFactory.php
 * 
 * Copyright (c) 2011 Emanuele Colonnelli <emanuele.colonnelli@php-struct.org>. 
 * 
 * This file is part of Expression program is undefined on line 8, column 40 in Templates/Licenses/license-gpl30.txt..
 * 
 * Expression program is undefined on line 10, column 19 in Templates/Licenses/license-gpl30.txt. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Expression program is undefined on line 15, column 19 in Templates/Licenses/license-gpl30.txt. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Expression program is undefined on line 21, column 30 in Templates/Licenses/license-gpl30.txt..  If not, see <http ://www.gnu.org/licenses/>.
 */
namespace org\phpstruct\db\ORM;
/**
 * Description of FieldFactory
 *
 * @author Emanuele Colonnelli <emanuele.colonnelli@php-struct.org>
 */
class FieldFactory {

    /**
     * Creates a specialization of the Field Abstract class, based on
     * value's data type
     *
     * @param string $fieldName
     * @param mixed $fieldValue
     * @return type\Lob
     */
    public static function factory($fieldName,$fieldValue){

        $type = Util::$typemap[\gettype($fieldValue)];

        $f = false;

        switch($type){
            case PDO::PARAM_BOOL:
                $f = new type\Bool($fieldName, $fieldValue);
                break;
            case PDO::PARAM_INT:
                $f = new type\Int($fieldName, $fieldValue);
                break;
            case PDO::PARAM_NULL:
                $f = new type\NNull($fieldName);
                break;
            case PDO::PARAM_STMT:
                break;
            case PDO::PARAM_STR:
                $f = new type\String($fieldName, $fieldValue);
                break;
            case PDO::PARAM_LOB:
                $f = new type\Lob($fieldName, $fieldValue);
                break;
        }
        return $f;
    }

}
